package com.huluobo.a2205kotlinjetpackdemo.news

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.google.gson.Gson
import com.huluobo.a2205kotlinjetpackdemo.R
import com.huluobo.a2205kotlinjetpackdemo.databinding.ActivityNewsBinding
import com.huluobo.base.bean.NewsBean
import com.huluobo.base.mvvm.BaseActivity
import com.huluobo.base.net.Const
import dagger.hilt.android.AndroidEntryPoint
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody

@AndroidEntryPoint
class NewsActivity : BaseActivity<ActivityNewsBinding, NewsViewModel>() {
    override fun initData() {
        val map = mutableMapOf<String, Int>()
        map[Const.PARAM_PAGE] = 0

        val json = Gson().toJson(map)
        val body = RequestBody.create(Const.MEDIA_TYPE.toMediaTypeOrNull(), json)
        vm.getNews(body)

        vm.getNewsSuccess.observe(this) {
            val list = Gson().fromJson(it, NewsBean::class.java)
            Log.i("TagA", "list:${list.size}")
        }
    }

    override fun initView() {
    }
}